
<!DOCTYPE html>
<html lang="">


<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
  <meta name="theme-color" content="#202020">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <script src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>
  
  
    <meta name="keywords" content>
  

  
    <meta name="description" content="iview-admin的介绍">
  
  
  
  <link rel="icon" type="image/x-icon" href="/images/footer-logo.png">
  
  <title>iview-admin的介绍 [ 51AIOps 专注于运维自动化  微信： kaipython ]</title>
  
    <!-- stylesheets list from config.yml -->
    
      <link rel="stylesheet" href="//cdn.bootcss.com/pure/1.0.0/pure-min.css">
    
      <link rel="stylesheet" href="/css/xoxo.css">
    
  
</head>


<body>
  <div class="nav-container">
    <nav class="home-menu pure-menu pure-menu-horizontal">
  <a class="pure-menu-heading" href="/">
    
    <span class="title" style="text-transform:none">51AIOps 专注于运维自动化  微信： kaipython</span>
  </a>

  <ul class="pure-menu-list clearfix">
      
          
            
              <li class="pure-menu-item"><a href="/" class="pure-menu-link">首页</a></li>
            
          
      
  </ul>
   
</nav>

  </div>

  <div class="container" id="content-outer">
    <div class="inner" id="content-inner" style='margin-left:-68px!important'>
      <div class="post-container">
  <article class="post" id="post">
    <header class="post-header text-center">
      <h1 class="title">
        iview-admin的介绍
      </h1>
      <span>
        
        <time class="time" datetime="2019-12-07T16:00:00.000Z">
        2019-12-08
      </time>
        
      </span>
      <span class="slash">/</span>
      <span class="post-meta">
      <span class="post-tags">
        
      </span>
    </span>
      <span class="slash">/</span>
      <span class="read">
      <span id="busuanzi_value_page_pv"></span> 点击
    </span>
      <span class="slash">/</span>
    </header>

    <div class="post-content">
      <h3 id="简单版下载地址"><a href="#简单版下载地址" class="headerlink" title="简单版下载地址"></a>简单版下载地址</h3><blockquote>
<p><a href="https://github.com/iview/iview-admin/tree/template" target="_blank" rel="noopener">https://github.com/iview/iview-admin/tree/template</a></p>
</blockquote>
<h3 id="安装准备"><a href="#安装准备" class="headerlink" title="安装准备"></a>安装准备</h3><ul>
<li>下载好<code>nodejs</code>， 有了<code>node</code>，也就有了<code>npm</code>的包管理工具</li>
<li>下载<a href="https://github.com/iview/iview-admin/tree/template" target="_blank" rel="noopener">https://github.com/iview/iview-admin/tree/template</a></li>
<li>安装好node之后，使用 <code>cnpm i</code> 安装依赖<ul>
<li>npm install iview 或者 npm install -g cnpm –registry=<a href="https://registry.npm.taobao.org" target="_blank" rel="noopener">https://registry.npm.taobao.org</a>  &amp;&amp; cnpm i</li>
</ul>
</li>
<li>安装完成之后，使用<code>npm run dev</code>运行项目</li>
</ul>
<h3 id="前后端分离之登录"><a href="#前后端分离之登录" class="headerlink" title="前后端分离之登录"></a>前后端分离之登录</h3><h4 id="前端修改的部分"><a href="#前端修改的部分" class="headerlink" title="前端修改的部分"></a>前端修改的部分</h4><p>第一步，修改<code>/Users/shangzekai/Downloads/iview-admin-template/src/view/login/login.vue</code>的值：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">export default &#123;</span><br><span class="line">  components: &#123;</span><br><span class="line">    LoginForm</span><br><span class="line">  &#125;,</span><br><span class="line">  methods: &#123;</span><br><span class="line">    ...mapActions([</span><br><span class="line">      &apos;handleLogin&apos;,</span><br><span class="line">      &apos;getUserInfo&apos;</span><br><span class="line">    ]),</span><br><span class="line">    handleSubmit (&#123; userName, password &#125;) &#123;</span><br><span class="line">      this.handleLogin(&#123; userName, password &#125;).then(res =&gt; &#123;</span><br><span class="line">          this.$router.go(&#123;name:&apos;home&apos;&#125;)</span><br><span class="line">				// 将如下的代码注释掉</span><br><span class="line">        // this.getUserInfo().then(res =&gt; &#123;</span><br><span class="line">        //   this.$router.push(&#123;</span><br><span class="line">        //     name: this.$config.homeName</span><br><span class="line">        //   &#125;)</span><br><span class="line">        // &#125;)</span><br><span class="line">      &#125;)</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>第二步, 修改 <code>/Users/shangzekai/Downloads/iview-admin-template/src/store/module/user.js</code></p>
<img src="/Users/shangzekai/Library/Application Support/typora-user-images/image-20201118144028602.png" alt="image-20201118144028602" style="zoom:50%;">

<p>第三步, 修改 <code>/Users/shangzekai/Downloads/iview-admin-template/src/store/module/user.js</code></p>
<img src="/Users/shangzekai/Library/Application Support/typora-user-images/image-20201118144324719.png" alt="image-20201118144324719" style="zoom:50%;">

<p>第四步， 注释掉<code>/Users/shangzekai/Downloads/iview-admin-template/src/mock/index.js</code>的代码：</p>
<img src="/Users/shangzekai/Library/Application Support/typora-user-images/image-20201118144742128.png" alt="image-20201118144742128" style="zoom:50%;">

<p>第五步， 在headers中传token</p>
<img src="/Users/shangzekai/Library/Application Support/typora-user-images/image-20201118201934149.png" alt="image-20201118201934149" style="zoom:50%;">

<h4 id="后端修改的部分："><a href="#后端修改的部分：" class="headerlink" title="后端修改的部分："></a>后端修改的部分：</h4><p>添加两个接口，登录的接口和获取用户权限信息的接口：</p>
<p>登录的接口:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Login</span><span class="params">(View)</span>:</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">post</span><span class="params">(self, request)</span>:</span></span><br><span class="line">        data = json.loads(request.body)</span><br><span class="line">        name = data.get(<span class="string">'userName'</span>)</span><br><span class="line">        pwd = data.get(<span class="string">'password'</span>)</span><br><span class="line"></span><br><span class="line">        userinfo = models.User.objects.filter(</span><br><span class="line">            name=name,</span><br><span class="line">            pwd=pwd</span><br><span class="line">        ).first()</span><br><span class="line"></span><br><span class="line">        jwt_data = &#123;</span><br><span class="line">            <span class="string">"name"</span>: userinfo.name,</span><br><span class="line">            <span class="string">"id"</span>: userinfo.id,</span><br><span class="line">        &#125;</span><br><span class="line">        jwt_encoded = JwtOperate().encode(jwt_data)</span><br><span class="line">        print(<span class="string">'jwtencode'</span>, jwt_encoded)</span><br><span class="line">        <span class="keyword">return</span> response.HttpOKResponse(jwt_encoded)</span><br></pre></td></tr></table></figure>

<p>获取用户权限信息的接口:</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> django.contrib.auth.models <span class="keyword">import</span> AnonymousUser</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">GetUserInfo</span><span class="params">(View)</span>:</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get</span><span class="params">(self, request)</span>:</span></span><br><span class="line">       </span><br><span class="line">       <span class="keyword">return</span> response.HttpOKResponse(request.user.employ_name)</span><br><span class="line">        <span class="comment"># request.user = AnonymousUser()</span></span><br></pre></td></tr></table></figure>

<p>中间件的实现：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"><span class="keyword">import</span> jwt</span><br><span class="line"><span class="keyword">import</span> logging</span><br><span class="line"><span class="keyword">from</span> django.utils.deprecation <span class="keyword">import</span> MiddlewareMixin</span><br><span class="line"><span class="keyword">from</span> django.contrib.auth.models <span class="keyword">import</span> AnonymousUser</span><br><span class="line"></span><br><span class="line">LOGGER = logging.getLogger(__name__)</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">JwtOperate</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    jwt操作</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line">        self._secret = <span class="string">"dsadsadsadewrewrew"</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">encode</span><span class="params">(self, payload: dict)</span> -&gt; str:</span></span><br><span class="line">        <span class="string">"""</span></span><br><span class="line"><span class="string">        jwt加密</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        :param payload:</span></span><br><span class="line"><span class="string">        :return:</span></span><br><span class="line"><span class="string">        """</span></span><br><span class="line">        <span class="keyword">return</span> jwt.encode(payload, self._secret, algorithm=<span class="string">'HS256'</span>).decode(<span class="string">"utf-8"</span>)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">decode</span><span class="params">(self, payload: str)</span> -&gt; dict:</span></span><br><span class="line">        <span class="string">"""</span></span><br><span class="line"><span class="string">        jwt解密</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        :param payload:</span></span><br><span class="line"><span class="string">        :return:</span></span><br><span class="line"><span class="string">        """</span></span><br><span class="line">        <span class="keyword">return</span> jwt.decode(payload, self._secret, algorithms=[<span class="string">'HS256'</span>])</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">AuthedUser</span>:</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self, username, employeeName, **kwargs)</span>:</span></span><br><span class="line">        self.employee_id = username</span><br><span class="line">        self.employ_name = employeeName</span><br><span class="line">        <span class="comment"># self.company_id = company_id</span></span><br><span class="line"></span><br><span class="line"><span class="meta">    @property</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">is_anonymous</span><span class="params">(self)</span>:</span></span><br><span class="line">        <span class="keyword">return</span> <span class="literal">False</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">AuthUserMiddleware</span><span class="params">(MiddlewareMixin)</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    统一认证中心中间件</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">process_request</span><span class="params">(self, request)</span>:</span></span><br><span class="line">        <span class="string">"""</span></span><br><span class="line"><span class="string">        从请求头中解析jwt的信息</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        :param request:</span></span><br><span class="line"><span class="string">        :return:</span></span><br><span class="line"><span class="string">        """</span></span><br><span class="line">        token = request.headers.get(<span class="string">"token"</span>)</span><br><span class="line">        <span class="keyword">if</span> token <span class="keyword">and</span> token != <span class="string">"undefined"</span>:</span><br><span class="line">            login_user_info = JwtOperate().decode(token)</span><br><span class="line"></span><br><span class="line">            request.user = AuthedUser(</span><br><span class="line">                employeeName=login_user_info[<span class="string">"name"</span>], username=login_user_info[<span class="string">"id"</span>],</span><br><span class="line">            )</span><br><span class="line">            <span class="keyword">return</span></span><br><span class="line">        request.user = AnonymousUser()</span><br></pre></td></tr></table></figure>

<p>配置文件的实现：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">MIDDLEWARE = [</span><br><span class="line">    <span class="string">'corsheaders.middleware.CorsMiddleware'</span>,</span><br><span class="line">    <span class="string">'django.middleware.security.SecurityMiddleware'</span>,</span><br><span class="line">    <span class="string">'django.contrib.sessions.middleware.SessionMiddleware'</span>,</span><br><span class="line">    <span class="string">'django.middleware.common.CommonMiddleware'</span>,</span><br><span class="line">    <span class="comment">#'django.middleware.csrf.CsrfViewMiddleware',</span></span><br><span class="line">    <span class="string">'django.contrib.auth.middleware.AuthenticationMiddleware'</span>,</span><br><span class="line">    <span class="string">'django.contrib.messages.middleware.MessageMiddleware'</span>,</span><br><span class="line">    <span class="string">'django.middleware.clickjacking.XFrameOptionsMiddleware'</span>,</span><br><span class="line">    <span class="string">'apps.common.middleware.AuthUserMiddleware'</span>,  <span class="comment">### 加上这句</span></span><br><span class="line">]</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> corsheaders.defaults <span class="keyword">import</span> default_headers,default_methods</span><br><span class="line"></span><br><span class="line">CORS_ALLOW_HEADERS = list(default_headers) + [</span><br><span class="line">    <span class="comment"># 'my-custom-header',</span></span><br><span class="line">    <span class="string">'token'</span>  <span class="comment">### 加上这个</span></span><br><span class="line">]</span><br></pre></td></tr></table></figure>

<p>后端JWT的实现：</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> jwt</span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">JwtOperate</span>:</span></span><br><span class="line">    <span class="string">"""</span></span><br><span class="line"><span class="string">    jwt操作</span></span><br><span class="line"><span class="string">    """</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">__init__</span><span class="params">(self)</span>:</span></span><br><span class="line">        self._secret = <span class="string">"dsadsadsadewrewrew"</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">encode</span><span class="params">(self, payload: dict)</span> -&gt; str:</span></span><br><span class="line">        <span class="string">"""</span></span><br><span class="line"><span class="string">        jwt加密</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        :param payload:</span></span><br><span class="line"><span class="string">        :return:</span></span><br><span class="line"><span class="string">        """</span></span><br><span class="line">        <span class="keyword">return</span> jwt.encode(payload, self._secret, algorithm=<span class="string">'HS256'</span>).decode(<span class="string">"utf-8"</span>)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">decode</span><span class="params">(self, payload: str)</span> -&gt; dict:</span></span><br><span class="line">        <span class="string">"""</span></span><br><span class="line"><span class="string">        jwt解密</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">        :param payload:</span></span><br><span class="line"><span class="string">        :return:</span></span><br><span class="line"><span class="string">        """</span></span><br><span class="line">        <span class="keyword">return</span> jwt.decode(payload, self._secret, algorithms=[<span class="string">'HS256'</span>])</span><br></pre></td></tr></table></figure>

<h3 id="图书管理系统之对出版社的管理"><a href="#图书管理系统之对出版社的管理" class="headerlink" title="图书管理系统之对出版社的管理"></a>图书管理系统之对出版社的管理</h3><h4 id="后端逻辑代码"><a href="#后端逻辑代码" class="headerlink" title="后端逻辑代码"></a>后端逻辑代码</h4><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> django.core.paginator <span class="keyword">import</span> Paginator</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Publish</span><span class="params">(View)</span>:</span></span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">get</span><span class="params">(self, request)</span>:</span></span><br><span class="line"></span><br><span class="line">        current_page = int(request.GET.get(<span class="string">'current_page'</span>))</span><br><span class="line">        <span class="comment"># 数据分页</span></span><br><span class="line">        paginator = Paginator(models.Publish.objects.all(), <span class="number">2</span>)</span><br><span class="line">        total = paginator.count</span><br><span class="line">        paginator_list = paginator.page(current_page).object_list</span><br><span class="line">        <span class="comment"># print(paginator_list)</span></span><br><span class="line"></span><br><span class="line">        publishes = [(model_to_dict(obj)) <span class="keyword">for</span> obj <span class="keyword">in</span> paginator_list]</span><br><span class="line">        <span class="comment"># print(publishes)</span></span><br><span class="line">        <span class="keyword">return</span> response.HttpOKResponse(&#123;</span><br><span class="line">            <span class="string">"publishs"</span>: publishes,</span><br><span class="line">            <span class="string">"total"</span>: total</span><br><span class="line">        &#125;)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">post</span><span class="params">(self, request)</span>:</span></span><br><span class="line">        data = json.loads(request.body)</span><br><span class="line">        models.Publish.objects.create(**data)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> response.HttpOKResponse(<span class="string">'添加成功'</span>)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">put</span><span class="params">(self, request)</span>:</span></span><br><span class="line">        data = json.loads(request.body)</span><br><span class="line">        id = data.get(<span class="string">'id'</span>)</span><br><span class="line">        ret = models.Publish.objects.filter(id=id).update(**data)</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> response.HttpOKResponse(<span class="string">'更新成功'</span>)</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">def</span> <span class="title">delete</span><span class="params">(self, request)</span>:</span></span><br><span class="line">        data = json.loads(request.body)</span><br><span class="line">        name = data.get(<span class="string">'name'</span>)</span><br><span class="line"></span><br><span class="line">        flag, res = models.Publish.objects.filter(name=name).delete()</span><br><span class="line">        <span class="keyword">if</span> flag:</span><br><span class="line">            <span class="keyword">return</span> response.HttpOKResponse(<span class="string">'删除成功'</span>)</span><br><span class="line">        <span class="keyword">else</span>:</span><br><span class="line">            <span class="keyword">return</span> response.HttpOKResponse(<span class="string">'出版社不存在'</span>)</span><br></pre></td></tr></table></figure>

<p>注意：使用postman进行接口的验证</p>
<h4 id="前端逻辑代码"><a href="#前端逻辑代码" class="headerlink" title="前端逻辑代码"></a>前端逻辑代码</h4><p>在 <code>/Users/shangzekai/web/iview-admin-simple/src/router/routers.js</code>中：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    path: &apos;/bookmanage&apos;,</span><br><span class="line">    name: &apos;bookmanage&apos;,</span><br><span class="line">    meta: &#123;</span><br><span class="line">      icon: &apos;logo-buffer&apos;,</span><br><span class="line">      title: &apos;图书管理测试&apos;</span><br><span class="line">    &#125;,</span><br><span class="line">    component: Main,</span><br><span class="line">    children: [</span><br><span class="line">      &#123;</span><br><span class="line">        path: &apos;/publisher&apos;,</span><br><span class="line">        name: &apos;publisher&apos;,</span><br><span class="line">        meta: &#123;</span><br><span class="line">          icon: &apos;md-arrow-dropdown-circle&apos;,</span><br><span class="line">          title: &apos;出版社管理&apos;</span><br><span class="line">        &#125;,</span><br><span class="line">        component: () =&gt; import(&apos;@/view/bookmanage/publisher.vue&apos;)</span><br><span class="line">      &#125;,</span><br><span class="line">      &#123;</span><br><span class="line">        path: &apos;/books&apos;,</span><br><span class="line">        name: &apos;book&apos;,</span><br><span class="line">        meta: &#123;</span><br><span class="line">          icon: &apos;md-trending-up&apos;,</span><br><span class="line">          title: &apos;书籍管理&apos;</span><br><span class="line">        &#125;,</span><br><span class="line">        component: () =&gt; import(&apos;@/view/bookmanage/book.vue&apos;)</span><br><span class="line">      &#125;</span><br><span class="line">    ]</span><br><span class="line">  &#125;,</span><br></pre></td></tr></table></figure>

<p>开始页面代码，在<code>/Users/shangzekai/web/iview-admin-simple/src/view/bookmanage/publisher.vue</code></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br></pre></td><td class="code"><pre><span class="line">&lt;div&gt;</span><br><span class="line">&lt;Table border :columns=&quot;publisher_column&quot; :data=&quot;publish_list&quot;&gt;</span><br><span class="line">      &lt;template slot-scope=&quot;&#123; row &#125;&quot; slot=&quot;id&quot;&gt;</span><br><span class="line">        &lt;strong&gt;&#123;&#123; row.id &#125;&#125;&lt;/strong&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">      &lt;template slot-scope=&quot;&#123; row &#125;&quot; slot=&quot;name&quot;&gt;</span><br><span class="line">        &lt;strong&gt;&#123;&#123; row.name &#125;&#125;&lt;/strong&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">      &lt;template slot-scope=&quot;&#123; row &#125;&quot; slot=&quot;city&quot;&gt;</span><br><span class="line">        &lt;strong&gt;&#123;&#123; row.city &#125;&#125;&lt;/strong&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">      &lt;template slot-scope=&quot;&#123; row &#125;&quot; slot=&quot;address&quot;&gt;</span><br><span class="line">        &lt;strong&gt;&#123;&#123; row.address &#125;&#125;&lt;/strong&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">      &lt;template slot-scope=&quot;&#123; row, index &#125;&quot; slot=&quot;action&quot;&gt;</span><br><span class="line">        &lt;Button type=&quot;primary&quot; size=&quot;small&quot; style=&quot;margin-right: 5px&quot; @click=&quot;show(index)&quot;&gt;View&lt;/Button&gt;</span><br><span class="line">        &lt;Button type=&quot;error&quot; size=&quot;small&quot; @click=&quot;remove(index)&quot;&gt;Delete&lt;/Button&gt;</span><br><span class="line">      &lt;/template&gt;</span><br><span class="line">    &lt;/Table&gt;</span><br><span class="line">    &lt;div style=&quot;margin-top: 10px&quot;&gt;</span><br><span class="line">      &lt;Page :total=&quot;total&quot; @on-change=&quot;changepage&quot; :page-size=&quot;2&quot; show-total/&gt;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">&lt;/div&gt;</span><br><span class="line"></span><br><span class="line">js中的代码：</span><br><span class="line"></span><br><span class="line">data () &#123;</span><br><span class="line">    return &#123;</span><br><span class="line">      publisher_column: [</span><br><span class="line">        &#123;</span><br><span class="line">          title: &apos;id&apos;,</span><br><span class="line">          slot: &apos;id&apos;</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          title: &apos;出版商名称&apos;,</span><br><span class="line">          slot: &apos;name&apos;</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          title: &apos;城市&apos;,</span><br><span class="line">          slot: &apos;city&apos;</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          title: &apos;地址&apos;,</span><br><span class="line">          slot: &apos;address&apos;</span><br><span class="line">        &#125;,</span><br><span class="line">        &#123;</span><br><span class="line">          title: &apos;Action&apos;,</span><br><span class="line">          slot: &apos;action&apos;,</span><br><span class="line">          width: 150,</span><br><span class="line">          align: &apos;center&apos;</span><br><span class="line">        &#125;	</span><br><span class="line">      ],</span><br><span class="line">      publish_list:[],</span><br><span class="line">      total: 0,</span><br><span class="line">      params:&#123;</span><br><span class="line">      	page:1,</span><br><span class="line">      &#125;,</span><br><span class="line">      current_page : 1,</span><br><span class="line">      id: &apos;&apos;,</span><br><span class="line">      addname: &apos;&apos;,</span><br><span class="line">      addcity: &apos;&apos;,</span><br><span class="line">      addaddress: &apos;&apos;,</span><br><span class="line">      upname: &apos;&apos;,</span><br><span class="line">      upcity: &apos;&apos;,</span><br><span class="line">      upaddress: &apos;&apos;,</span><br><span class="line">      add_publish_modal: false,</span><br><span class="line">      update_publish_modal: false</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>docker启动gitlab的方式:</p>
<blockquote>
<p><a href="https://www.cnblogs.com/anliven/p/12070966.html" target="_blank" rel="noopener">https://www.cnblogs.com/anliven/p/12070966.html</a></p>
</blockquote>

    </div>

  </article>
  <div class="toc-container">
    
  <div id="toc" class="toc-article">
    <strong class="toc-title">目录</strong>
    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#简单版下载地址"><span class="toc-text">简单版下载地址</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#安装准备"><span class="toc-text">安装准备</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#前后端分离之登录"><span class="toc-text">前后端分离之登录</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#前端修改的部分"><span class="toc-text">前端修改的部分</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#后端修改的部分："><span class="toc-text">后端修改的部分：</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#图书管理系统之对出版社的管理"><span class="toc-text">图书管理系统之对出版社的管理</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#后端逻辑代码"><span class="toc-text">后端逻辑代码</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#前端逻辑代码"><span class="toc-text">前端逻辑代码</span></a></li></ol></li></ol>
  </div>


  </div>
</div>
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=5sr5du46f27&amp;m=0&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33" async="async"></script>
<div class="copyright">
    <span>本作品采用</span>
    <a href="https://creativecommons.org/licenses/by/4.0/">知识共享署名 4.0 国际许可协议</a>
    <span>进行许可。 转载时请注明原文链接。</span>
</div>


  
    <div class="post-nav" style="margin-left:-168px;">
      <div class="post-nav-item post-nav-next">
        
          <span>〈 </span>
          <a href="/2019/11/09/Django的cookie和session介绍/" rel="next" title="第二十三章 Django cookie 与 session">
          第二十三章 Django cookie 与 session
          </a>
        
      </div>
  
      <div class="post-nav-item post-nav-prev">
          
          <a href="/2019/12/08/Django的分页/" rel="prev" title="Django的分页">
            Django的分页
          </a>
          <span>〉</span>
        
      </div>
    </div>
  


	
	<div style="width:109%; margin-left:-144px" id="lv-container" data-id="city" data-uid="MTAyMC80OTg5NS8yNjM4Ng==">
	<script type="text/javascript">
   	   (function(d, s) {
       		var j, e = d.getElementsByTagName(s)[0];

       		if (typeof LivereTower === 'function') { return; }

       		j = d.createElement(s);
       		j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
       		j.async = true;

       		e.parentNode.insertBefore(j, e);
   	   })(document, 'script');
	</script>
	<noscript> 为正常使用来必力评论功能请激活JavaScript</noscript>
        </div>
	



    </div>

    

  </div>
  <footer class="footer text-center">
    <div id="bottom-inner">
        <a class="bottom-item" href target="_blank">GitHub</a> |
        <a class="bottom-item" href>友情链接</a> |
        <a class="bottom-item" href="https://hexo.io" target="_blank">Powered by hexo</a> |
        <a class="bottom-item" href="https://github.com/fooying/hexo-theme-xoxo-plus" target="_blank">Theme xoxo-plus</a> |
        <a class="bottom-item" href="/atom.xml">订阅</a>
    </div>
</footer>

  

<script>
  (function(window, document, undefined) {

    var timer = null;

    function returnTop() {
      cancelAnimationFrame(timer);
      timer = requestAnimationFrame(function fn() {
        var oTop = document.body.scrollTop || document.documentElement.scrollTop;
        if (oTop > 0) {
          document.body.scrollTop = document.documentElement.scrollTop = oTop - 50;
          timer = requestAnimationFrame(fn);
        } else {
          cancelAnimationFrame(timer);
        }
      });
    }

    var hearts = [];
    window.requestAnimationFrame = (function() {
      return window.requestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.oRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        function(callback) {
          setTimeout(callback, 1000 / 60);
        }
    })();
    init();

    function init() {
      css(".heart{z-index:9999;width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");
      attachEvent();
      gameloop();
      addMenuEvent();
    }

    function gameloop() {
      for (var i = 0; i < hearts.length; i++) {
        if (hearts[i].alpha <= 0) {
          document.body.removeChild(hearts[i].el);
          hearts.splice(i, 1);
          continue;
        }
        hearts[i].y--;
        hearts[i].scale += 0.004;
        hearts[i].alpha -= 0.013;
        hearts[i].el.style.cssText = "left:" + hearts[i].x + "px;top:" + hearts[i].y + "px;opacity:" + hearts[i].alpha + ";transform:scale(" + hearts[i].scale + "," + hearts[i].scale + ") rotate(45deg);background:" + hearts[i].color;
      }
      requestAnimationFrame(gameloop);
    }

    /**
     * 给logo设置点击事件
     * 
     * - 回到顶部
     * - 出现爱心
     */
    function attachEvent() {
      var old = typeof window.onclick === "function" && window.onclick;
      var logo = document.getElementById("logo");
      if (logo) {
        logo.onclick = function(event) {
          returnTop();
          old && old();
          createHeart(event);
        }
      }
      
    }

    function createHeart(event) {
      var d = document.createElement("div");
      d.className = "heart";
      hearts.push({
        el: d,
        x: event.clientX - 5,
        y: event.clientY - 5,
        scale: 1,
        alpha: 1,
        color: randomColor()
      });
      document.body.appendChild(d);
    }

    function css(css) {
      var style = document.createElement("style");
      style.type = "text/css";
      try {
        style.appendChild(document.createTextNode(css));
      } catch (ex) {
        style.styleSheet.cssText = css;
      }
      document.getElementsByTagName('head')[0].appendChild(style);
    }

    function randomColor() {
      // return "rgb(" + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + ")";
      return "#F44336";
    }

    function addMenuEvent() {
      var menu = document.getElementById('menu-main-post');
      if (menu) {
        var toc = document.getElementById('toc');
        if (toc) {
          menu.onclick = function() {
            if (toc) {
              if (toc.style.display == 'block') {
                toc.style.display = 'none';
              } else {
                toc.style.display = 'block';
              }
            }
          };
        } else {
          menu.style.display = 'none';
        }
      }
    }

  })(window, document);
</script>

  



  

</body>
</html>
